﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WFNetLib;
using System.Net;
using WFNetLib.StringFunc;
using Common;

namespace 生命体征测试仪
{
    public class WebWork
    {
        public static bool bInternet()
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "CheckNet", SysConfig.SysConfigFilePath);//"http://www.baidu.com";
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static RegResult bServer()
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                string id = StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), "");
                url = url + "webAPI/TELogin.aspx?ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                SetSystemDateTime.SetSystemData(Convert.ToDateTime(ret.DateTime));
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult TEPulse()
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                string id = StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), "");
                url = url + "webAPI/TEPulse.aspx?ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult UserLogin(string id)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/UserLogin.aspx?ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult UserReg(UserInfoData user)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/UserReg.aspx";
                string post=WFJSON.JsonSerializerBySingleData<UserInfoData>(user);
                HttpWebResponse hr = WebResponse.CreatePostHttpResponse(url,post);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult Set_fujianqingdan()
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);                
                string id = StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), "");
                url = url + "webAPI/Set_fujianqingdan.aspx?ID=";
                url = url + id;
                url = url + "&fujianqingdan=" + SysConfig.fjqd.ToString();
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                SetSystemDateTime.SetSystemData(Convert.ToDateTime(ret.DateTime));
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult SaveMedicalResult(MedicalResultData MedicalResult)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/SaveMedicalResult.aspx";
                string post = WFJSON.JsonSerializerBySingleData<MedicalResultData>(MedicalResult);
                HttpWebResponse hr = WebResponse.CreatePostHttpResponse(url, post);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static MedicalResultList QueryMedicalResultList(string type,string id)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/QueryMedicalResultList.aspx?type="+type+"&ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                MedicalResultList ret = WFJSON.JsonDeserializeBySingleData<MedicalResultList>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static MedicalResultList QueryMedicalResultList(string type,string id,string d1,string d2)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/QueryMedicalResultList_byTime.aspx?type=" + type + "&ID=";
                url = url + id+"&d1="+d1+"&d2="+d2;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                MedicalResultList ret = WFJSON.JsonDeserializeBySingleData<MedicalResultList>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static MedicalResultData QueryMedicalResult(string type,string id, string d1)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/QueryMedicalResult.aspx?type=" + type + "&ID=";
                url = url + id + "&d1=" + d1;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                MedicalResultData ret = WFJSON.JsonDeserializeBySingleData<MedicalResultData>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult CheckRecord(string id)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/CheckRecord.aspx?workid=";
                url = url + id + "&teid=" + StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), "");
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static NurseList QueryNurse(string teid)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/GetNurse.aspx?ID=";
                url = url + teid;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                NurseList ret = WFJSON.JsonDeserializeBySingleData<NurseList>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult AddNurse(NurseData nurse)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/AddNurse.aspx";
                string post = WFJSON.JsonSerializerBySingleData<NurseData>(nurse);
                HttpWebResponse hr = WebResponse.CreatePostHttpResponse(url, post);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static RegResult DeleteNurse(string id)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/DeleteNurse.aspx?ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                RegResult ret = WFJSON.JsonDeserializeBySingleData<RegResult>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
        public static TEPartList QueryOffline(string id)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string url;
                url = iniFileOP.Read("Web Set", "WorkAddr", SysConfig.SysConfigFilePath);
                url = url + "webAPI/GetOffline.aspx?ID=";
                url = url + id;
                HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url);
                TEPartList ret = WFJSON.JsonDeserializeBySingleData<TEPartList>(WebResponse.Content);
                return ret;
            }
            catch
            {
                return null;
            }
        }
    }
}
